package cn.itcast.bos.repository;

import cn.itcast.bos.domain.base.Courier;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Think on 2017/9/16.
 */
@Repository
public interface CourierRepository extends JpaRepository<Courier,Integer>,JpaSpecificationExecutor<Courier> {
    @Query(value = "update Courier set deltag='1' where id = ?1")
    @Modifying
    public void updateDelTag(Integer id);

    @Query(value = "update Courier set deltag='' where id = ?1")
    @Modifying
    public void restoreDelTag(Integer id);

    /**
     * inner join：表示将查询的结果放置到Object[]数组中，数组的第一个位置，存放快递员，数组的第二个位置，存放定区
     * inner join fetch：将封装结果封装到from关键字后面的对象中，只返回Courier
     */
    @Query(value="from Courier c inner join fetch  c.fixedAreas f where f.id = ?")
    List<Courier> findAssociationCourier(String fixedAreaId);
}
